window.onload=function (){
    var roomLeftAmounts;
    var ls=[];
    ls[0]=document.getElementById("tehui");
    ls[1]=document.getElementById("yaju");
    ls[2]=document.getElementById("siren");
    ls[3]=document.getElementById("miren");
    ls[4]=document.getElementById("qinlv");
    ls[5]=document.getElementById("xingzhen");
    ls[6]=document.getElementById("yule");
    ls[7]=document.getElementById("qinzi");

    //var setCheckDate=document.getElementById("setCheckDate");
    axios({
        method: 'get',
        url: '/RoomController/countAllRoomsLeftAmount'
    }).then(function (resp) {
        roomLeftAmounts = resp.data.data;
        // console.log(roomLeftAmounts);
        for (var i=0;i<ls.length;i++){
            ls[i].lastElementChild.innerHTML=roomLeftAmounts[i];
        }
    });
    var roomtbody=document.getElementById("roomtbody");
    var roomFormNum=8;
    var now=new Date();
    now=now.getFullYear()+'-'+((now.getMonth()+1)<10?('0'+(now.getMonth()+1)):(now.getMonth()+1))+'-'+now.getDate();
    for (var i=0;i<roomFormNum;i++){
        roomtbody.children[i].children[4].firstElementChild.value=now;
    }
    document.getElementById("setCheckDate").onclick=function (){
        var checkedToReserveList=[];
        var dataInfo={};
        for (var i=0;i<roomFormNum;i++){
            //判断多选框是否被选中
            if (roomtbody.children[i].children[0].firstElementChild.checked==true){
                var selectElem=roomtbody.children[i].children[6].firstElementChild;
                //console.log(roomtbody.children[i].children[4].firstElementChild.value)
                dataInfo={
                    "roomLevelID":i+5,
                    "passengerID":sessionStorage.getItem("userid"),
                    "payWayID":selectElem.options[selectElem.selectedIndex].value,
                    "arriveTime":roomtbody.children[i].children[4].firstElementChild.value,
                    "deposit":roomtbody.children[i].children[3].innerHTML,
                    "predetermineStateID":52,
                    "predetermineDay":roomtbody.children[i].children[5].firstElementChild.value
                };
                checkedToReserveList.push(dataInfo);
            }

        }

        // console.log(checkedToReserveList);
        for (var i=0;i<checkedToReserveList.length;i++){
            axios({
                method: 'post',
                url: '/ReservationController/insertAll',
                data: checkedToReserveList[i]
            }).then(function (resp) {
                alert('预定成功！');
                window.location.reload();
            });
        }
    }
}